

<template>
  <el-dialog :model-value="dialogDetail" title="记录详情" :width="660" draggable @close="handleClose">
    <el-form :model="form" label-width="70px">
      <el-form-item label="品类">
        <el-input v-model="form.categoryName" disabled />
      </el-form-item>
      <el-form-item label="品名">
        <el-input v-model="form.name" disabled />
      </el-form-item>
      <el-form-item label="品牌">
        <el-input v-model="form.brand" disabled />
      </el-form-item>
      <el-form-item label="规格型号">
        <el-input v-model="form.specification" disabled />
      </el-form-item>
      <el-form-item label="单位">
        <el-input v-model="form.unit" disabled />
      </el-form-item>
      <el-form-item label="单价">
        <el-input v-model="form.unitPrice" disabled />
      </el-form-item>
      <el-form-item label="数量">
        <el-input v-model="form.quantity" disabled />
      </el-form-item>
      <el-form-item label="供应商">
        <el-input v-model="form.supplier" disabled />
      </el-form-item>
      <el-form-item label="状态">
        <el-input v-model="form.status" disabled />
      </el-form-item>
      <el-form-item label="部门编码">
        <el-input v-model="form.deptId" disabled />
      </el-form-item>
      <el-form-item label="部门名称">
        <el-input v-model="form.deptName" disabled />
      </el-form-item>
      <el-form-item label="使用人编号">
        <el-input v-model="form.userId" disabled />
      </el-form-item>
      <el-form-item label="使用人姓名">
        <el-input v-model="form.userName" disabled />
      </el-form-item>
      <el-form-item label="购置日期">
        <el-input v-model="form.phurchaseDate" disabled />
      </el-form-item>
      <el-form-item label="报废日期">
        <el-input v-model="form.cancelDate" disabled />
      </el-form-item>
      <el-form-item label="审核状态">
        <el-input v-model="form.audit_flag" disabled />
      </el-form-item>
      <el-form-item label="采购单编号">
        <el-input v-model="form.purchaseId" disabled />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.memo" type="textarea" class="el-long-style" disabled>
        </el-input>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup lang='ts'>
import { defineEmits, ref, defineProps, watch } from 'vue'
import { addYhpList, findCategory, findCatelog, updateYhpList } from "@/api/lvcManage/yhpApplication";
import { ElMessage } from 'element-plus'

const props = defineProps(['dialogDetailValue'])

const formRef = ref(null)
//form表单数据
const form = ref({
  catalog_id: '', //品名id
  name: '',     //品名
  category_id: '', //品类id
  categoryName: '',   //品类
  brand: '',    //品牌
  specification: '',   //规格型号
  unit: '',     //单位
  unitPrice: '',   //单价
  quantity: '',    //数量
  supplier: '',    //供应商
  status: '',      //状态
  deptId: '',      //部门编码
  deptName: '',    //部门名称
  userId: '',      //使用人编号
  userName: '',    //使用人姓名
  phurchaseDate: '',  //购置日期
  cancelDate: '',     //报废日期
  audit_flag: '',     //审核状态
  purchaseId: '',     //采购单编号
  memo: ''            //备注
})

watch(
  () => props.dialogDetailValue,
  () => {
    form.value = props.dialogDetailValue
    console.log(form.value)
  }, { deep: true, immediate: true })



//对话框关闭方法
const emits = defineEmits(['update:modelValue'], ['func'])
const handleClose = () => {
  emits('update:modelValue', false)
}

//根据类别id查询所有易耗品
const CATELOG_DATA = ref([])   //易耗品
//获取所有的：低值易耗品类别
const CATEGORY_DATA = ref([])   //品类数据
const findCategory_F = async () => {
  const response = await findCategory()
  CATEGORY_DATA.value = response.data
  //for(let i=0; i<response.data.length; i++) {  //response.data是对象，不能直接赋给CATEGORY_DATA，需要取出name
  //  CATEGORY_DATA.value[i] = response.data[i].name
  //}
}
findCategory_F()


const findCatelog_F = async (id) => {   //id代表当前被选中的品类
  CATELOG_DATA.value = null
  console.log('----------------')
  const response = await findCatelog(id)
  CATELOG_DATA.value = response.data
  console.log(response.data)
}

const add_data = ref({
  empId: '',  //当前的操作人id
  empName: '', //当前操作人名称
  operation: '修改', //这里统一为录入
  form1: JSON.stringify(form.value) //添加条件
})
//修改方法
const handleConfirm = async () => {
  add_data.value.empId = localStorage.getItem('empId')    //取出存在本地的用户id
  add_data.value.empName = localStorage.getItem('empName') //取出存在本地的用户名
  add_data.value.form1 = JSON.stringify(form.value) //取出form里的数据存到form1里
  const response = await updateYhpList(add_data.value)   //发送添加请求
  emits('func')
  //添加成功后，清空数据,并提示成功
  //form.value = {}
  ElMessage({
    message: '添加成功！',
    type: 'success',
  })
  //添加成功关闭对话框,调用handleClose（）函数
  handleClose()
}
</script>

<style scoped>

</style>
